package cn.tsoft.drp.phoneMessage;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.tsoft.drp.sms.utils.SmsUtils;


public class PhoneMessageServlet extends HttpServlet{
	
//	private String URL="http://sdkhttp.eucp.b2m.cn/sdkproxy";
//	public static String softwareSerialNo="0SDK-ESH-0130-LFUUO";//软件序列号,请通过亿美销售人员获取
//	public static String key="888888";//序列号首次激活时自己设定    
//	public static String password="008388";// 密码,请通过亿美销售人员获取
//	private String URL="http://dx.lmobile.cn:6003/submitdata/Service.asmx/g_Submit";
//	public static String softwareSerialNo="0SDK-ESH-0130-LFUUO";//软件序列号,请通过亿美销售人员获取
//	public static String key="888888";//序列号首次激活时自己设定    
//	String PostData = "sname=kdldemo&spwd=123&scorpid=&sprdid=1012802&sdst=13818304474,13661560140,12452,15811637370&smsg=nihaodfni";
	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req,resp);
	}

//		System.out.println(URL+"/sendsms.action?cdkey="+softwareSerialNo+"&password="+key+"&phone="+phone+"&message="+message);
//		RequestDispatcher rd = req.getRequestDispatcher(URL+"/sendsms.action?cdkey="+softwareSerialNo+"&password="+key+"&phone="+phone+"&message="+message);
//		rd.forward(req, resp);
//		resp.sendRedirect(URL+"/sendsms.action?cdkey="+softwareSerialNo+"&password="+key+"&phone="+phone+"&message="+message);
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		//账号
		String sname = req.getParameter("sname");
		//密码
		String spwd = req.getParameter("spwd");
		//产品编号
		String sprdid="";
		String URL="";
		//使用快速通道
		if(req.getParameter("isSpeed")!=null && !req.getParameter("isSpeed").equals("")){
			 sprdid =SmsUtils.getValue("speedSprdid");
			 URL = SmsUtils.getValue("speedURL");
		}else{//普通通道
			 sprdid =SmsUtils.getValue("sprdid");
			 URL = SmsUtils.getValue("smsDXurl");
		}
		//手机号码
		String phone  = req.getParameter("phone");
		//消息内容
		String message = req.getParameter("message");
		//要执行的方法
		String method =  req.getParameter("method");
		String PostData ="sname="+sname+"&spwd="+spwd+"&scorpid=&sprdid="+sprdid;
		if(phone!=null ){
			PostData += "&sdst="+phone+"&smsg="+java.net.URLEncoder.encode(message,"utf-8");
		}
		System.out.println("==="+URL+"/"+method+"?"+PostData);
		String url = URL+"/"+method+"?"+PostData ;
		resp.sendRedirect(url);
	}
	
}
